//app.js
App({
    onLaunch: function () {

    },

    getUserInfo: function (cb) {
        var that = this
        if (this.globalData.userInfo) {
            typeof cb == "function" && cb(this.globalData.userInfo)
        } else {
            //调用登录接口
            wx.getUserInfo({
                withCredentials: false,
                success: function (res) {
                    that.globalData.userInfo = res.userInfo
                    typeof cb == "function" && cb(that.globalData.userInfo)
                }
            })
        }
    },

    // 倒计时
    count_down: function (over_time, current_time) {
        let show_time = over_time - current_time
        let h, m, s;
        h = parseInt(show_time / 3600);
        m = parseInt((show_time - (h * 3600)) / 60);
        s = parseInt(show_time - (h * 3600) - (m * 60));
        h < 10 ? h = '0' + h : null;
        m < 10 ? m = '0' + m : null;
        s < 10 ? s = '0' + s : null;
        return ({ h, m, s })
    },
    /** 倒计时处理 两个参数
     * 
     * ctime 现在时间和结束时间相差的秒数  ctime
     * param 返回的结果 d==>带天数 h==>时分秒
    */

    countDown: function (ctime) {
        let d='', h, m, s, result ,ctime2;
        if (ctime>86400){  //大于 一 天
            d = parseInt(ctime / 86400);
            ctime2 = parseInt(ctime - (d * 86400));
        }else{
            ctime2 = ctime;
        }

        
        h = parseInt(ctime2 / 3600);
        m = parseInt((ctime2 - (h * 3600)) / 60);
        s = parseInt(ctime2 - (h * 3600) - (m * 60));
        
        h < 10 ? h = '0' + h : null;
        m < 10 ? m = '0' + m : null;
        s < 10 ? s = '0' + s : null;

        d == '' ? result = { h, m, s } : result = {d, h, m, s }

        return result;
    },


    navigateTo: function (url) {
        wx.navigateTo({ url: url })
    },
    redirectTo:function (url){
        wx.redirectTo({url:url})  
    },

})
